home *** CD-ROM | disk | FTP | other *** search
- unit UnitChart;
-
- interface
-
- { This unit configures a Chart1 component with the parameters
- passed to the WebModule ISAPI dll.
-
- See the TeeISAPI.htm page parameters.
- }
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, TeeProcs, TeEngine, Chart, Series, StdCtrls,
- { added units... }
- JPEG, HTTPApp;
-
- type
- TForm2 = class(TForm)
- Chart1: TChart;
- Series1: TPieSeries;
- Label1: TLabel;
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- Function ChartToJPEG(Request:TWebRequest):TJPEGImage;
- end;
-
- implementation
-
- {$R *.DFM}
-
- { Add some sample values... }
- procedure TForm2.FormCreate(Sender: TObject);
- begin
- With Series1 do
- begin
- Clear;
- Add( 143450, 'USA', clBlue );
- Add( 128950, 'Europe', clGreen );
- Add( 64345, 'Australia', clRed );
- Add( 34589, 'Asia', clYellow );
- Add( 7111, 'Africa', clWhite );
- end;
- end;
-
- { This function creates a TJPEGImage and draws a TeeChart on it }
- Function GetChartJPEG(AChart:TCustomChart; Params:TJPEGDefaults):TJPEGImage;
- var tmpBitmap:TBitmap;
- begin
- result:=TJPEGImage.Create; { <-- create a TJPEGImage }
- tmpBitmap:=TBitmap.Create; { <-- create a temporary TBitmap }
- try
- tmpBitmap.Width :=AChart.Width; { <-- set the bitmap dimensions }
- tmpBitmap.Height:=AChart.Height;
- { draw the Chart on the temporary Bitmap... }
- AChart.Draw(tmpBitmap.Canvas,Rect(0,0,tmpBitmap.Width,tmpBitmap.Height));
- { set the desired JPEG options... }
- With result do
- begin
- GrayScale :=Params.GrayScale;
- ProgressiveEncoding :=Params.ProgressiveEncoding;
- CompressionQuality :=Params.CompressionQuality;
- PixelFormat :=Params.PixelFormat;
- ProgressiveDisplay :=Params.ProgressiveDisplay;
- Performance :=Params.Performance;
- Scale :=Params.Scale;
- Smoothing :=Params.Smoothing;
- { Copy the temporary Bitmap onto the JPEG image... }
- Assign(tmpBitmap);
- end;
- finally
- tmpBitmap.Free; { <-- free the temporary Bitmap }
- end;
- end;
-
- { Get the HTML parameters and change the Chart... }
- Function TForm2.ChartToJPEG(Request:TWebRequest):TJPEGImage;
-
- Function GetBoolField(Const AField:String):Boolean;
- begin
- result:=Uppercase(Request.ContentFields.Values[AField])=Uppercase(AField);
- end;
-
- Procedure PrepareChart(AChart:TCustomChart);
-
- Function GetRequestSeriesType:TChartSeriesClass;
- var tmpSt:String;
- begin
- result:=TPieSeries;
- tmpSt:=Uppercase(Request.ContentFields.Values['type']);
- if tmpSt='BAR' then result:=TBarSeries else
- if tmpSt='HORIZBAR' then result:=THorizBarSeries else
- if tmpSt='LINE' then result:=TLineSeries else
- if tmpSt='AREA' then result:=TAreaSeries else
- if tmpSt='PIE' then result:=TPieSeries else
- if tmpSt='POINT' then result:=TPointSeries else
- if tmpSt='FASTLINE' then result:=TFastLineSeries;
- end;
-
- Procedure AddDataToSeries;
- var t:Integer;
- tmpLabel,
- tmpValue:String;
- begin
- AChart.Series[0].Clear;
- for t:=1 to 100 do { max number of points for this example }
- begin
- tmpLabel:=Request.ContentFields.Values['text'+IntToStr(t)];
- tmpValue:=Request.ContentFields.Values['value'+IntToStr(t)];
- if tmpValue='' then
- break
- else
- AChart.Series[0].Add(StrToFloat(tmpValue),tmpLabel,clTeeColor);
- end;
- end;
-
- Procedure ChangeMarkStyle;
- var tmpSt:String;
- begin
- tmpSt:=Uppercase(Request.ContentFields.Values['mark']);
- With AChart.Series[0].Marks do
- if tmpSt='VALUE' then Style:=smsValue else
- if tmpSt='PERCENT' then Style:=smsPercent else
- if tmpSt='LABEL' then Style:=smsLabel;
- end;
-
- Procedure ChangeLegendStyle;
- var tmpSt:String;
- begin
- tmpSt:=Uppercase(Request.ContentFields.Values['legendstyle']);
- With AChart.Legend do
- if tmpSt='VALUE' then TextStyle:=ltsLeftValue else
- if tmpSt='PERCENT' then TextStyle:=ltsLeftPercent else
- if tmpSt='LABEL' then TextStyle:=ltsPlain;
- end;
-
- Procedure ChangeLegendPosition;
- var tmpSt:String;
- begin
- tmpSt:=Uppercase(Request.ContentFields.Values['legendposition']);
- With AChart.Legend do
- if tmpSt='LEFT' then Alignment:=laLeft else
- if tmpSt='RIGHT' then Alignment:=laRight else
- if tmpSt='TOP' then Alignment:=laTop else
- if tmpSt='BOTTOM' then Alignment:=laBottom;
- end;
-
- Procedure ChangeBarStyle;
- var tmpSt:String;
- begin
- tmpSt:=Uppercase(Request.ContentFields.Values['barstyle']);
- With AChart[0] as TCustomBarSeries do
- if tmpSt='RECTANGLE' then BarStyle:=bsRectangle else
- if tmpSt='PYRAMID' then BarStyle:=bsPyramid else
- if tmpSt='INVPYRAMID' then BarStyle:=bsInvPyramid else
- if tmpSt='CYLINDER' then BarStyle:=bsCilinder else
- if tmpSt='ELLIPSE' then BarStyle:=bsEllipse else
- if tmpSt='ARROW' then BarStyle:=bsArrow else
- if tmpSt='RECTGRADIENT' then BarStyle:=bsRectGradient;
- end;
-
- begin
- ChangeAllSeriesType(AChart,GetRequestSeriesType);
- AddDataToSeries;
- ChangeMarkStyle;
- ChangeLegendStyle;
- ChangeLegendPosition;
- if AChart[0] is TCustomBarSeries then ChangeBarStyle;
-
- With AChart do
- begin
- Series[0].Marks.Visible:=GetBoolField('MARKS');
- Legend.Visible:=GetBoolField('LEGEND');
-
- Title.Text.Clear;
- Title.Text.Add(Request.ContentFields.Values['titletext']);
-
- Title.Visible:=GetBoolField('TITLE');
- Gradient.Visible:=GetBoolField('GRADIENT');
-
- Chart3DPercent:=StrToInt(Request.ContentFields.Values['percent3D']);
- end;
- end;
-
- var Params:TJPEGDefaults;
- begin
- PrepareChart(Chart1); { <-- change Chart properties }
-
- { Create the JPEG image parameters }
- With Params do
- begin
- GrayScale:= GetBoolField('grayscale');
- ProgressiveEncoding:=False;
- CompressionQuality:= StrToInt(Request.ContentFields.Values['jpegquality']);
- PixelFormat:=jf24bit;
- ProgressiveDisplay:=True;
- Performance:=jpBestQuality;
- Scale:=jsFullSize;
- Smoothing:=False;
- end;
- { Create and return the JPEG component with the Chart image }
- result:=GetChartJPEG(Chart1,Params);
- end;
-
- end.
-